fix(pool): prune stale worktree registrations before add in Acquire#31
Open
e-jung wants to merge 2 commits into
Open
fix(pool): prune stale worktree registrations before add in Acquire#31e-jung wants to merge 2 commits into
e-jung wants to merge 2 commits into
Conversation
A crashed or forcibly removed worktree leaves prunable bookkeeping in .git/worktrees/. The next "treehouse get" then fails hard with "missing but already registered worktree" because git refuses the add, wedging every subsequent spawn until a human runs "git worktree prune" by hand. Run "git worktree prune" immediately before "git worktree add" in Acquire's create-new-worktree branch. Prune is safe by design: it only removes registrations whose target directories are already gone, so it cannot destroy live worktrees or data. Adds TestGetRecoversFromStaleWorktreeRegistration covering the recovery. Refs kunchenguid#30
2835921 to
0ed4610
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
acquirenow runsgit worktree prunebefore adding a worktree, so a stale registration left behind by a crashed or forcibly removed worktree no longer wedgesgetwith a "missing but already registered worktree" error.git.PruneWorktreeshelper (internal/git/git.go) that shells out togit worktree prune, which only removes registrations for already-missing directories.TestGetRecoversFromStaleWorktreeRegistratione2e regression test and documentedget's self-healing behavior inREADME.mdandAGENTS.md.Risk Assessment
✅ Low: The change is a small, well-bounded, self-healing fix: a single safe
git worktree prunecall (only removes registrations for already-missing directories) placed beforegit worktree addin the create-new path, serialized under the existing flock, with a well-constructed e2e test.Testing
Confirmed the self-healing intent end-to-end: with a prunable stale worktree registration planted at the slot path, the pre-fix binary's
getwedges with "missing but already registered worktree" (exit 1, dir not recreated), while the fixed binary'sgetprunes it and successfully creates the worktree (exit 0, README.md recreated, returned to pool). The accompanying unit/e2e test passes on the fix and fails on the base commit, and the entirego test ./...suite is green. No UI/rendered surface applies to this CLI change; evidence is captured as CLI transcripts.Evidence: Combined before/after CLI demo (pre-fix fails, fixed recovers)
PRE-FIX (base 68fa3d2): === treehouse get === exit code: 1 failed to create worktree: git worktree add --detach .../myrepo-435da5/1/myrepo main: fatal: '...' is a missing but already registered worktree; use 'add -f' to override, or 'prune' or 'remove' to clear --- worktree dir recreated? --- NO: .../1/myrepo/README.md MISSING FIXED (target 0ed4610): === treehouse get === exit code: 0 Setting up worktree... Entered worktree at ~/.treehouse/myrepo-a8be86/1/myrepo. Type 'exit' to return. Worktree returned to pool. --- git worktree list AFTER get --- (prunable entry is gone) --- worktree dir recreated? --- YES: .../1/myrepo/README.md existsEvidence: New e2e test run against BASE source proves it catches the regression
Source: New e2e test run against BASE source proves it catches the regression (local file:
/tmp/no-mistakes-evidence/01KW9VEPA2WGD9GH7HH0HJ7AQZ)Evidence: Reproducible demo script (sets up repo, plants stale registration, runs get)
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
go test ./cmd/ -run TestGetRecoversFromStaleWorktreeRegistration -v (passes on target commit)go test ./... (full suite, all packages pass)Ran the new e2e test against the base commit source (68fa3d2) — FAILS with the exact bug, confirming it is a valid regression testManual end-to-end CLI reproduction with /tmp/treehouse-base (pre-fix): simulated a crashed scout by registering a worktree at Acquire's slot path then deleting its dir;treehouse getfailed with 'fatal: ... is a missing but already registered worktree' (exit 1)Manual end-to-end CLI reproduction with /tmp/treehouse-fixed (this change): same scenario;treehouse getsucceeded (exit 0), pruned the prunable entry, recreated the worktree dir with README.md, and printed 'Entered worktree at ...' + 'Worktree returned to pool.'✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.